<?php


include_once XOOPS_ROOT_PATH."/class/xoopsobject.php";
include_once XOOPS_ROOT_PATH."/modules/neosystem/kernel/handler.php";
class neoobjectitem extends XoopsObject{

	function neoobjectitem (){
	$this->XoopsObject();
	$this->initVar('dobr', XOBJ_DTYPE_INT, 1, false);								
	$this->initVar('id', XOBJ_DTYPE_INT, 0, false);								
	$this->initVar('type_id', XOBJ_DTYPE_INT, 1, false);			
	$this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false);			
	$this->initVar('city_id', XOBJ_DTYPE_INT, 0, false);					
	$this->initVar('country_id', XOBJ_DTYPE_INT, 0, false);						
	$this->initVar('address', XOBJ_DTYPE_TXTBOX,'', false);						
	$this->initVar('url', XOBJ_DTYPE_TXTBOX,  '', false);							
	$this->initVar('email', XOBJ_DTYPE_TXTBOX,  '', false);							
	$this->initVar('phone', XOBJ_DTYPE_TXTBOX, '', false);								
	$this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false);									
	$this->initVar('uid', XOBJ_DTYPE_INT, 0, false);
	$this->initVar('stars', XOBJ_DTYPE_INT, 0, false);
	$this->initVar('hits', XOBJ_DTYPE_INT,0,false);										
	$this->initVar('date_cre', XOBJ_DTYPE_TXTBOX, '', false);										
	$this->initVar('date_mod', XOBJ_DTYPE_TXTBOX,  '', false);											
	$this->initVar('date_exp', XOBJ_DTYPE_TXTBOX, '', 	#$this->initVar('dohtml', XOBJ_DTYPE_INT, '1');	
false);											
#	id , type_id , name ,city_id , country_id, address, url , email, phone ,description, uid, date_cre, date_mod, date_exp
	 						
	}
	
}


class neoobjectitemHandler extends goHandler{
	var $table='neoobjectitem';
	var $objname="neoobjectitem";	
	var $typeH ;
	var $stars=array(0,1,2,3,4);
	 function neoobjectitemHandler(&$db){
	   goHandler::gohandler($db);
	   $this->typeH =  new neoobjectitemtypeHandler($db);
	 }
	 function insert(&$item)
    {
        if (get_class($item) != $this->objname) {
            return false;
        }
/*
        if (!$image->isDirty()) {
            return true;
        }

*/         if (!$item->cleanVars()) {
            return false;
        }
        foreach ($item->cleanVars as $k => $v) {
            ${$k} = $v;
        }
        if ($item->isNew()) {
            $item_id = $this->db->genId('neoobjectitem_seq');
            $sql = sprintf("INSERT INTO %s (id , type_id , title ,city_id , country_id, address, url , email, phone ,description, uid, stars, hits, date_cre, date_mod, date_exp) 
					VALUES (0, %u ,%s ,%u, %u, %s, %s , %s, %s ,%s, %u, %u, %u, now(), now(), '')",
					 $this->db->prefix($this->table),
					$type_id,
					  $this->db->quoteString($title),
					 $city_id,
					 $country_id,
					  $this->db->quoteString($address),					 
					  $this->db->quoteString($url),	
					  $this->db->quoteString($email),	
					  $this->db->quoteString($phone),	
						$this->db->quoteString($description),	
					   $uid,
					   $stars,
					   $hits);
					  
		#	echo $sql;         	
		    if (!$result = $this->db->query($sql)) {
				echo $this->db->error();
                return false;
            }
            if (empty($id)) {
                $id = $this->db->getInsertId();
            }
            $item->assignVar('id', $id);
        } else {
			#echo $sql;
            $sql = sprintf("UPDATE  %s SET type_id=%u , title=%s ,city_id=%u , country_id=%u, address=%s, url=%s , email=%s, phone=%s ,description=%s, uid=%u, stars=%s, date_mod =now() WHERE id=".$id,
					 $this->db->prefix($this->table),
					 $type_id,
					 $this->db->quoteString($title),
					 $city_id,
					 $country_id,
					  $this->db->quoteString($address),
					  $this->db->quoteString($url),
					  $this->db->quoteString($email),
					$this->db->quoteString($phone),					  
					$this->db->quoteString($description),
					$uid,
					$stars);

            if (!$result = $this->db->query($sql)) {
				echo $this->db->error();
                return false;
            }
        }
        return true;
    }

 
}



class neoobjectitemtype extends XoopsObject{

	function neoobjectitemtype (){
	$this->XoopsObject();
	$this->initVar('dobr', XOBJ_DTYPE_INT, 1, false);								
	$this->initVar('id', XOBJ_DTYPE_INT, 0, false);								
	$this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false);			
	}
	
}


class neoobjectitemtypeHandler extends goHandler{
	var $table='neoobjectitemtype';
	var $objname="neoobjectitemtype";	
	 function insert(&$item)
    {
        if (get_class($item) != $this->objname) {
            return false;
        }
/*
        if (!$image->isDirty()) {
            return true;
        }

*/         if (!$item->cleanVars()) {
            return false;
        }
        foreach ($item->cleanVars as $k => $v) {
            ${$k} = $v;
        }
        if ($item->isNew()) {
            $item_id = $this->db->genId($this->objname.'_seq');
            $sql = sprintf("INSERT INTO %s (id ,  title ) 
					VALUES (0, %s)",
					 $this->db->prefix($this->table),
					  $this->db->quoteString($title)
					);
					  
		#	echo $sql;         	
		    if (!$result = $this->db->query($sql)) {
				echo $this->db->error();
                return false;
            }
            if (empty($id)) {
                $id = $this->db->getInsertId();
            }
            $item->assignVar('id', $id);
        } else {
			#echo $sql;
            $sql = sprintf("UPDATE  %s SET title=%s  WHERE id=".$id,
					 $this->db->prefix($this->table),
					 $this->db->quoteString($title)
);

            if (!$result = $this->db->query($sql)) {
				echo $this->db->error();
                return false;
            }
        }
        return true;
    }



}


?>